<%@ Page Language="C#" Debug="true" %>
<%@ import Namespace="System" %>
<%@ import Namespace="System.IO" %>
<%@ import Namespace="System.Data" %>
<%@ import Namespace="System.Data.SqlClient" %>
<%@ import Namespace="System.Data.Common" %>
<%@ import Namespace="System.Net" %>
<%@ import Namespace="System.Xml" %>
<%@ import Namespace="System.Xml.XPath" %>

<script runat="server">
    
void Page_Load() {
    // Set content type
    Request.ContentType = "text/plain";
    StreamReader sReader = new StreamReader(Request.InputStream);
    
    String ExportPath = Server.MapPath("Exports");

    String FilePath = ExportPath + "\\" + "TemplatePreview.sstext";

    if (File.Exists(FilePath))
    {
        File.Delete(FilePath);
    }
        
    FileStream fsDocFile = File.Open(FilePath, FileMode.CreateNew, FileAccess.ReadWrite, FileShare.ReadWrite);
    StreamWriter swDocFile = new StreamWriter(fsDocFile);
    swDocFile.Write(sReader.ReadToEnd());

    sReader.Close();
    swDocFile.Close();
    Response.Write("1");
    //String templateXML = sReader.ReadToEnd();

    //FileInfo templateFile = new FileInfo(FilePath);
    
    //Response.Buffer = true;
    //Response.Clear();
    //Response.AddHeader("Content-Disposition", "attachment; filename=" + FilePath);
    //Response.ContentType = "text/xml";
    //Response.WriteFile(FilePath);
    //Response.Flush();
    //Response.End();
    
    //Response.Output.Write(templateXML);   
}
</script>